package com.example.s06_themeleaf.controller;

import com.example.s06_themeleaf.pojo.User;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.ArrayList;
import java.util.List;

@Controller
public class HelloController
{
    @RequestMapping("/hello")
    public String hello(Model m)
    {

        m.addAttribute("message","Hello world!!!!");
        return "1helloworld";
    }


    @GetMapping("/test2")
    public String test2(Model m)
    {
        m.addAttribute("username","张三");
        return "2string";
    }

    @GetMapping("/test3")
    public String test3(Model m,String flag)
    {
        m.addAttribute("flag",flag);
        return "3if";
    }


    @GetMapping("/test4")
    public String test4(Model m)
    {
        List<User> list = new ArrayList<>();
        list.add(new User("张三",18,"123456"));
        list.add(new User("张四",19,"123456"));
        list.add(new User("张三分",20,"123456"));

        m.addAttribute("list",list);

        return "4list";
    }


    @GetMapping("/test5")
    public String test5(Model m)
    {
        m.addAttribute("type","link");
        m.addAttribute("pageId","springboot/2022/03/30/");
        m.addAttribute("img","https://fc5tn.baidu.com/it/u=188818894,1323916671&fm=202");
        return "5url";
    }



    @RequestMapping("/test6")
    public String test6(Model map) {
        map.addAttribute("sex", "man");
        return "6switch";
    }


    @GetMapping("/test7")
    public String test7(Model m)
    {
        m.addAttribute("userName","张三");
        m.addAttribute("userId","15");
        return "7inline";
    }

}
